package main

import "fmt"

type Student struct {
	Name    string
	Age     int8
	Score   int8
	TianCai string
}

type CollegeStudent struct {
	Student
	//People
	//有名结构体，使用时，必须带上名字
	p       People
	Address string
}

type CollegeStudent2 struct {
	*Student
	//People
	//有名结构体，使用时，必须带上名字
	p       *People
	Address string

	//同样也可以使用匿名基本数据
	int
}

type People struct {
	Name string
	sex  int8
}

//继承的基本语法
func main() {
	var coll CollegeStudent
	coll.Address = "henan"
	coll.TianCai = "tiancai"
	//赋值不明确，编译会出错
	//如果子结构体继承连个父结构体，并且属性存在重名，并且子结构体属性不与父结构体重名
	//则在下面使用时，会报错
	//coll.Name = "tom"
	coll.Student.Name = "jetty"

	//有名结构体使用方式,必须加上名字
	coll.p.Name = "sfs"

	//继承的初始化
	colstu := CollegeStudent{Student: Student{Name: "tom2", Age: 2, Score: 23}, p: People{"cshi", 2}, Address: "fsdf"}
	fmt.Println(colstu)

	colstu2 := CollegeStudent2{Student: &Student{Name: "tom2", Age: 2, Score: 23}, p: &People{"cshi", 2}, Address: "fsdf", int: 12}
	//匿名字段是基本数据类型
	colstu2.int = 100
	fmt.Println(*colstu2.Student, *colstu2.p, colstu2.Name)
}
